Skip to content

fix: report zero native balance and gas#304

Merged
sadiq1971 merged 2 commits into
mainfrom
fix/canton-token
Jun 8, 2026
Merged

fix: report zero native balance and gas#304
sadiq1971 merged 2 commits into
mainfrom
fix/canton-token

Conversation

@sadiq1971

Copy link
Copy Markdown
Member

Problem

The EVM JSON-RPC facade reported a fake 1000-coin native balance and a 1 gwei gas price purely to satisfy MetaMask's client-side pre-flight check (balance >= value + gasLimit*gasPrice). The fake balance is confusing — a user with no native coin sees 1000 in MetaMask.

Fix

There is no native gas token, so report 0. Because the facade only accepts zero-value ERC-20 transfers, MetaMask's check collapses to 0 >= 0 — so transfers still go through as long as gas is also 0. This requires zeroing every fee surface MetaMask reads (gas price, maxPriorityFeePerGas, block baseFeePerGas, receipt effectiveGasPrice), not just eth_gasPrice.

Since the gas price and the cosmetic gas limit are fixed values rather than per-deployment knobs, they are hardcoded in code and removed from config:

  • native balance → always 0 (token.Native.GetBalance)
  • gas price → always 0 across eth_gasPrice, maxPriorityFeePerGas, block baseFeePerGas, receipt effectiveGasPrice
  • gas limitservice.DefaultGasLimit (21000), cosmetic only

Removed from config: eth_rpc.gas_price_wei, eth_rpc.gas_limit, eth_rpc.native_balance_wei (the last was a dead field — never read), and token.native_balance_wei. Also dropped the now-dead token.Service.isUserRegistered.

The relayer's ethereum.gas_limit (real on-chain gas for actual Ethereum txs) is unaffected — only the api-server facade's cosmetic values changed.

Notes

  • Verify against a live MetaMask: a zero-gas chain can occasionally surface soft warnings. If that happens, the values can be reintroduced — but the balance/gas coupling must be preserved (both 0, or both non-zero).
  • go build, go vet, and the full test suite pass.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request simplifies the Ethereum JSON-RPC facade by hardcoding gas-related values to zero and removing corresponding configuration parameters (native_balance_wei, gas_price_wei, and gas_limit). Specifically, GasPrice, MaxPriorityFeePerGas, EffectiveGasPrice, and BaseFeePerGas now always return 0, while native token GetBalance also always reports 0. This change ensures MetaMask compatibility for zero-value ERC-20 transfers without requiring a fake native balance. Tests and configuration files have been updated accordingly. No review comments were provided, so there is no additional feedback to address.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@codecov-commenter

codecov-commenter commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@16ffa3e). Learn more about missing BASE report.

Files with missing lines Patch % Lines
pkg/app/api/server.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #304   +/-   ##
=======================================
  Coverage        ?   30.49%           
=======================================
  Files           ?      150           
  Lines           ?    11260           
  Branches        ?        0           
=======================================
  Hits            ?     3434           
  Misses          ?     7554           
  Partials        ?      272           
Flag Coverage Δ
unittests 30.49% <93.33%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/ethrpc/service/service.go 79.87% <100.00%> (ø)
pkg/token/config.go 83.33% <100.00%> (ø)
pkg/token/native.go 100.00% <100.00%> (ø)
pkg/token/service.go 55.00% <ø> (ø)
pkg/app/api/server.go 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

The EVM facade reported a fake 1000-coin native balance and a 1 gwei
gas price so MetaMask's `balance >= value + gasLimit*gasPrice` pre-flight
check would pass. The fake balance is confusing — users with no native
coin see 1000.

There is no native gas token, so report 0. Since the facade only accepts
zero-value ERC-20 transfers, MetaMask's check collapses to `0 >= 0` as
long as gas is also 0, so transfers still go through.

Gas price and the cosmetic gas limit are fixed values, not deployment
knobs, so hardcode them in code and drop them from config:
- native balance: always 0 (token.Native.GetBalance)
- gas price: always 0 (eth_gasPrice, maxPriorityFeePerGas, baseFeePerGas,
  effectiveGasPrice)
- gas limit: service.DefaultGasLimit (21000), cosmetic only

The relayer's ethereum.gas_limit (real on-chain gas) is unaffected.
@sadiq1971 sadiq1971 merged commit 6d552df into main Jun 8, 2026
3 checks passed
@sadiq1971 sadiq1971 deleted the fix/canton-token branch June 8, 2026 14:33
salindne added a commit that referenced this pull request Jun 11, 2026
PR #304 (in v0.5.2) removed NativeBalanceWei from both token.Config
and ethrpc.Config. The heredoc still emitted token.native_balance_wei,
which strict YAML unmarshal rejects:

  yaml: unmarshal errors:
    line 36: field native_balance_wei not found in type token.Config

Just drop the line — the new schema doesn't need it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants